package controllers;

import java.util.ArrayList;
import java.util.Iterator;

import lib.Observer;
import lib.Subject;
import global.ControllerRegistry;

public abstract class ControllerAbstract implements Subject, Observer
{
	/**
	 * list of observers that require notification (for MVC, see GoF Observer Design Pattern)
	 */
	protected ArrayList<Observer> observers = new ArrayList<Observer>(); 

	public abstract String getShortName();
	public void registerController()
	{
		ControllerRegistry.getInstance().registerController(this);
	}
	public void addObserver( Observer o ) 
	{
        observers.add( o );
	}
	/**
	 * Detach observer from this model
	 */
	public void removeObserver( Observer o ) 
	{
        observers.remove( o );
	}
	/**
	 * loop through and notify each observer
	 */
	protected void notifyObservers() 
	{
      Iterator i = observers.iterator();
      while( i.hasNext() ) 
      {
            Observer o = ( Observer ) i.next();
            o.update( this );
      }
	}
	
}
